package org.example.code.test2024.eight_mouth;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class test0801 {
    public List<String> test01(List<String> list){
        List<String> list2 = new ArrayList<>();
        for (String a :list) {
            if(list2.contains(a)){//判断是否重复
                continue;
            }
            list2.add(a);
        }
        return  list2;
    }

    public List<String> test02(Map<String,Integer> map){
        List<String> list = new ArrayList<>();
        for (String key:map.keySet()) {
            if(list.size()<3){//集合为空则直接添加
                list.add(key);
            }else{
                System.out.println(list.size());
                int n = list.size();
                for (int i=0;i<n;i++) {
                    if(map.get(list.get(i))<map.get(key)){//比较
                        list.remove(i);//更新集合值
                        list.add(key);
                        break;
                    }
                }
            }
        }
        return list;
    }

    public Map<String,Integer> test03(List<String> list){
        Map<String,Integer> map = new HashMap<>();
        for (String a:list) {
            if(map.containsKey(a)){
                map.put(a,map.get(a)+1);
            }else{
                map.put(a,1);
            }
        }
        return map;
    }

    public Map<String,List<String>> test04(List<String> list){
        List<String> nums = new ArrayList<>();
        List<String> chars = new ArrayList<>();
        for (String a:list) {
            if(a.charAt(0)>'0'&&a.charAt(0)<'9'){
                nums.add(a);
            }else{
                chars.add(a);
            }
        }
        Map<String,List<String>> map = new HashMap<>();
        map.put("数字列表",nums);
        map.put("字母列表",chars);
        return map;
    }

    public Map<String,Double> test05(Map<String,List<Integer>> map){
        Map<String,Double> result = new HashMap<>();
        for (String a:map.keySet()) {
            List<Integer> integers = map.get(a);
            double sum = 0.0;
            for (Integer b:integers) {
                sum=sum+b;
            }
            sum=sum/integers.size();
            result.put(a,sum);
        }
        return result;
    }

    public Map<String,String> test06(List<String> list){
        Map<String,String> map = new HashMap<>();
        for (String a:list) {
            String[] split = a.split(",");
//            System.out.println(split[0]+"   "+split[1]);
            map.put(split[1],split[0]);
        }
        return map;
    }

    public static void main(String[] args) {
       List<String> lsit = new ArrayList<>();
       lsit.add("aqq,shadjks");
        lsit.add("awq,skahsdj");
        lsit.add("123,sbjcabsc");
        lsit.add("235,skjasda");
//        lsit.add("casd");
//        lsit.add("aasc");
        System.out.println(new test0801().test06(lsit));
    }
}
